<!DOCTYPE html>
<html style="height: 100%">
<head>
    <title>活动首页</title>
    <% include ../../layouts/import.ejs %>
</head>
<body style="height: 100%">

<% include ../../layouts/header.ejs %>

<% include ../../layouts/processHeader.ejs %>


    <div class="container " role="navigation">

        <div class="activity-list">
            <div id="activityToolbar" class="btn-group" role="group" aria-label="...">
                <button type="button" class="btn btn-default " id="activityAdd">添加
                </button>
                <!--<button type="button" class="btn btn-default" id="activityEdit">修改</button>-->
                <!--<button type="button" class="btn btn-default" id="activityDelete">删除</button>-->
            </div>

            <div class="condition-search pull-right">
                <span>按条件查询：</span>
                <label class="checkbox-inline">
                    <input type="checkbox" name="activityType" value="0" data-multifilter="0"> 里程碑
                </label>
                <label class="checkbox-inline">
                    <input type="checkbox" name="activityType" value="1" data-multifilter="1"> 版本升级
                </label>
                <label class="checkbox-inline">
                    <input type="checkbox" name="activityType" value="2" data-multifilter="2"> 用户反馈
                </label>
            </div>
            <div class="clearfix"></div>
            <table id="activityDataTable" class="activity-list-table">

            </table>
        </div>

    </div>


<% include ../../layouts/footer.ejs %>
</body>

<script>

    $("#activity").addClass("click-change")
    $("input:checkbox[name='activityType']").click(function () {
        var checked = [];
        $('input:checkbox:checked').each(function () {
            checked.push($(this).val());
        });
        $('#activityDataTable').bootstrapTable(
                'refresh',
                {
                    url: '/process/activity/search',
                    query: {
                        activityType: checked
                    }
                }
        );
    })


    var activityDataTable = $('#activityDataTable').bootstrapTable({
        striped: true,
        showExport: true,                     //是否显示导出
        exportDataType: "basic",              //basic', 'all', 'selected'.
        showToggle: true,
        pagination: true,
        pageNumber: 1,
        pageSize: 15,
        pageList: [5, 10, 15, 20],
        search: true,
        toolbarAlign: 'left',
        toolbar: '#activityToolbar',
        url: '/process/activity/listByActivity',
        columns: [
            {
                field: 'activity_name',
                title: '活动主题',
                align: 'center',
                valign: 'middle',
                width: '30%'
            }, {
                field: 'activity_date',
                align: 'center',
                title: '活动日期',
                valign: 'middle',
                width: '15%'
            }, {
                field: 'activity_type',
                align: 'center',
                title: '活动类型',
                valign: 'middle',
                width: '15%',
                formatter: function (value, row, index) {
                    var valueStr = '';
                    switch (value) {
                        case 0:
                            valueStr = '<span class="glyphicon glyphicon-flag filtr-item" data-category="1" style="padding-right: 5px;color: #5cd29d"></span>' +
                                    '<span>里程碑</span>';
                            break;
                        case 1:
                            valueStr = '<span class="glyphicon glyphicon-upload filtr-item" data-category="2" style="padding-right: 5px;color:#F8A500;"></span>' +
                                    '<span>版本升级</span>';
                            break;
                        case 2:
                            valueStr = '<span class="glyphicon glyphicon-share filtr-item" data-category="3" style="padding-right: 5px;color: #00C2F8"></span>' +
                                    '<span>用户反馈</span>';
                            break;
                    }
                    return valueStr;
                }
            }, {
                field: 'event',
                title: '事件',
                valign: 'middle',
                width: '30%'
            }, {
                field: 'Button',
                title: '操作',
                width: '10%',
                valign: 'middle',
                align: 'center',
                formatter: function (value, row, index) {
                    var id = row.id;
                    var result = "";
                    result += "<a href='/process/activity/edit/"+ id +"' class='btn btn-xs blue'  title='编辑'><span class='glyphicon glyphicon-pencil'></span></a>";
                    result += "<a href='javascript:;' class='btn btn-xs red'  onclick=\"deleteById('" + id + "')\" title='删除'><span class='glyphicon glyphicon-remove'></span></a>";

                    return result;
                }
            }
        ],
        rowStyle: function (row, index) {
            var strclass = "";
            if (row.activity_type == "0") {
                strclass = 'success filtr-item';

            }
            else if (row.activity_type == "1") {
                strclass = 'danger filtr-item';
            }
            else if (row.activity_type == "2") {
                strclass = 'info filtr-item';
            }
            else {
                return {};
            }
            return {
                classes: strclass
            }
        },
        rowAttributes: function rowAttributes(row, index) {
            var activity_index = "";
            if (row.activity_type == "0") {
                activity_index = '0';
            }
            else if (row.activity_type == "1") {
                activity_index = '1';
            }
            else if (row.activity_type == "2") {
                activity_index = '2';
            }
            else {
                return {};
            }
            return {
                'data-category': activity_index
            }
        }

    });



    $('#activityAdd').click(function () {
        location.href = '/process/activity/add';
    });

    function deleteById(id) {
        if (id) {
            $.post('/process/activity/delete/' + id, function (result) {
                console.log(result.errcode)
                if (result.errcode === 0) {
                    $('#activityDataTable').bootstrapTable(
                            'refresh',
                            {
                                silent: true,
                                url: '/process/activity/listByActivity'
                            }
                    );
                } else {
                    console.error(result.message);
                }
            })
        } else {
            return false;
        }
    }
</script>
</html>